package com.bgs.eat.memberType.service.Impl;

import com.bgs.eat.memberType.entity.MemberTypeEntity;
import com.bgs.eat.memberType.mapper.MemberTypeMapper;
import com.bgs.eat.memberType.service.MemberTypeService;
import com.bgs.eat.page.MyPageHelper;
import com.bgs.eat.page.PageRequest;
import com.bgs.eat.page.PageResult;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName MemberTypeServiceImpl
 * @Description TODO 会员类型管理（后端）
 * @Author G胖
 * @Date 2022-10-12 上午 11:39
 **/
@Service
public class MemberTypeServiceImpl implements MemberTypeService {

    @Resource
    MemberTypeMapper memberTypeMapper;

    /**
     * @Author G胖
     * @Description 新增会员类型 （后端）
     * @Date 2022-10-12 上午 11:44
     * @Return com.bgs.eat.config.CommonResult

     */
    @Override
    public Integer saveMemberType(MemberTypeEntity memberTypeEntity) {
        memberTypeEntity.setDelFlag(0);
        return memberTypeMapper.insertSelective(memberTypeEntity);
    }

    /**
     * @Author G胖
     * @Description 校验新增修改时会员名称是否重复（后端）
     * @Date 2022-10-12 上午 11:47
     * @Return com.bgs.eat.config.CommonResult

     */
    @Override
    public MemberTypeEntity checkMembertypeName(String memberName) {
        MemberTypeEntity memberTypeEntity = new MemberTypeEntity();
        memberTypeEntity.setMemberName(memberName);
        return memberTypeMapper.selectOne(memberTypeEntity);
    }

    /**
     * @Author G胖
     * @Description 会员类型分页全查+模糊查（会员名称） 后端
     * @Date 2022-10-12 下午 02:29
     * @Return com.bgs.eat.page.PageResult

     */
    @Override
    public PageResult getMemberTypeByPage(PageRequest pageRequest, String memberName) {
        MyPageHelper.startPage(pageRequest);
        Example example = new Example(MemberTypeEntity.class);
        example.createCriteria().andLike("memberName","%"+memberName+"%").andEqualTo("delFlag",0);
        PageResult pageResult = MyPageHelper.pageInfo(memberTypeMapper.selectByExample(example));
        return pageResult;
    }

    /**
     * @Author G胖
     * @Description 修改会员类型（后端）
     * @Date 2022-10-12 下午 02:37
     * @Return com.bgs.eat.config.CommonResult

     */
    @Override
    public Integer updateMemberType(MemberTypeEntity memberTypeEntity) {
        return memberTypeMapper.updateByPrimaryKeySelective(memberTypeEntity);
    }

    /**
     * @Author G胖
     * @Description 删除会员类型（后端）
     * @Date 2022-10-12 下午 02:38
     * @Return com.bgs.eat.config.CommonResult

     */
    @Override
    public Integer deleteMemberType(Integer id) {
        MemberTypeEntity memberTypeEntity = new MemberTypeEntity();
        memberTypeEntity.setId(id);
        memberTypeEntity.setDelFlag(1);
        return memberTypeMapper.updateByPrimaryKeySelective(memberTypeEntity);
    }

    /**
     * @Author G胖
     * @Description 会员价格管理查询会员类型 （后端）
     * @Date 2022-10-12 下午 03:46
     * @Return

     */
    @Override
    public List<MemberTypeEntity> getSelectMemberType() {
        MemberTypeEntity memberTypeEntity = new MemberTypeEntity();
        memberTypeEntity.setDelFlag(0);
        return memberTypeMapper.select(memberTypeEntity);
    }

    /**
     * @Author G胖
     * @Description 查询会员id （后端）
     * @Date 2022-10-12 下午 04:43
     * @Return com.bgs.eat.config.CommonResult

     */
    @Override
    public MemberTypeEntity getEatMemberId(String memberName) {
        MemberTypeEntity memberTypeEntity = new MemberTypeEntity();
        memberTypeEntity.setMemberName(memberName);
        return memberTypeMapper.selectOne(memberTypeEntity);
    }
}
